﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Sql;

public partial class Default2 : System.Web.UI.Page
{
    DcSql conn;
    private string VT_Prim = "Prim";
    private string VT_MikroDB = "MikroDB";
    private string ay, yil;

    protected void Page_Load(object sender, EventArgs e)
    {
        conn = new DcSql();
        conn.DBBaglan(VT_Prim);



        DcSql connMikroDB = new DcSql();
        string HataMesaji = connMikroDB.DBBaglan(VT_MikroDB);

        string selectsql = "select 'TÜM BÖLGELER'  as bol_ismi  union all SELECT bol_ismi from CARI_HESAP_BOLGELERI ";
        DataSet dsMikro = new DataSet();
        SqlDataAdapter daMikro = new SqlDataAdapter(selectsql, connMikroDB.GetConn());

        daMikro.Fill(dsMikro, "BOLGE");


        cmbBolge1.TextField = "bol_ismi";
        cmbBolge1.ValueField = "bol_ismi";
        cmbBolge1.DataSource = dsMikro.Tables[0];
        cmbBolge1.DataBind();


    }
    protected void btnHesapla_Click(object sender, EventArgs e)
    {

        yil = ASPxSpinEdit1.Value.ToString();
        ay = (cmbAy.SelectedIndex + 1).ToString();

        string selectsql = " select cari_per_RECno,sPersonelKodu,cari_per_adi,sum(PrimTutari) as PrimTutari,sum(BonusTutari) as BonusTutari,sum(PrimTutari)+sum(BonusTutari) as ToplamTutar from  " +
                           " ( "+
                           " select sPersonelKodu,cari_per_adi ,cari_per_RECno," +
                           " case when nPrimBonus=1 then nPrimBonusTutari else 0 end PrimTutari , "+
                           " case when nPrimBonus=2 then nPrimBonusTutari else 0 end BonusTutari  "+
                           " from PrimBonus a,mikroDB.dbo.CARI_PERSONEL_TANIMLARI b "+
                           " where a.sPersonelKodu = b.cari_per_kod collate TURKISH_CI_AS "+
                           " and nPrimBonusYil=" + yil + " and nPrimBonusAy=" + ay +
                           " ) x "+
                           " group by cari_per_RECno,sPersonelKodu,cari_per_adi ";


        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(selectsql, conn.GetConn());

        da.Fill(ds, "PrimBonus");

        gridListe.Visible = true;
        gridListe.DataSource = ds.Tables[0];
        gridListe.DataBind();

        if (!IsPostBack && !IsCallback)
            gridListe.DataBind();
    }
}